package com.ruoyi.websocket;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionChoice;
import com.volcengine.ark.runtime.model.completion.chat.ChatCompletionRequest;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
import com.volcengine.ark.runtime.service.ArkService;
import java.util.List;
public class apiRequest {
    static String apiKey = "c9da33a0-72cb-46d7-bde9-b86721989aa9";
    static ArkService service = ArkService.builder().apiKey(apiKey).baseUrl("https://ark.cn-beijing.volces.com/api/v3/").build();
    public static String request(List<ChatMessage> messages) {

        ChatCompletionRequest chatCompletionRequest = ChatCompletionRequest.builder()
                .model("ep-20250302105750-j6vcs")
                .messages(messages)
                .build();

        // 返回响应结果
        ChatCompletionChoice choice = service.createChatCompletion(chatCompletionRequest).getChoices().get(0);
        String reply = choice.getMessage().stringContent();
        // 关闭服务器
        service.shutdownExecutor();
        System.out.println("服务器发送消息" + reply);
        return reply;
    }
}
